//
//  ZYCHomeRootHeaderView.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/18.
//

#import "ZYCHomeRootHeaderView.h"
#import <SDCycleScrollView.h>
#import "BTRootImageTItleVIew.h"
#import "ZYCWheelBannerModel.h"
@interface ZYCHomeRootHeaderView ()<SDCycleScrollViewDelegate,BTRootImageTitleViewDelegate>

@property (nonatomic, strong) UIImageView *topImageView;
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView1;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView2;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView3;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView4;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView5;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView6;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView7;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView8;
@end
@implementation ZYCHomeRootHeaderView

- (void)setWheelBannerList:(NSArray *)wheelBannerList{
    _wheelBannerList = wheelBannerList;
    NSMutableArray *tempArr = [NSMutableArray arrayWithCapacity:0];
    for (ZYCWheelBannerModel *model in wheelBannerList) {
        NSString *imgUrl = [[NSString stringWithFormat:@"%@/zd-system-service%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"sdfz_url"],model.path] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        [tempArr addObject:imgUrl];
    }
    _cycleScrollView.imageURLStringsGroup = tempArr.copy;
}


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = HEX_RGB(@"#FAFAFA");
        [self addSubview:self.topImageView];
        [self addSubview:self.cycleScrollView];
        [self addSubview:self.imageTitleView1];
        [self addSubview:self.imageTitleView2];
        [self addSubview:self.imageTitleView3];
        [self addSubview:self.imageTitleView4];
        [self addSubview:self.imageTitleView5];
        [self addSubview:self.imageTitleView6];
        [self addSubview:self.imageTitleView7];
        [self addSubview:self.imageTitleView8];
        [self setupConstraints];
    }
    return self;
}

- (void)setupConstraints{
    
    [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self);
        make.height.mas_equalTo(180.0f);
    }];
    
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10.f);
        make.right.offset(-10.f);
        make.top.offset(kStatusBarHeight);
        make.height.mas_equalTo((kScreenWidth - 20) / (710 / 300));
    }];
    
    CGFloat w = (kScreenWidth - 18) / 4;
    CGFloat h = w;
    
    CGFloat margin = 9;//(kScreenWidth - 60 * 4) / 5;
    
    [self.imageTitleView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(margin);
        make.top.equalTo(self.cycleScrollView.mas_bottom).offset(13.f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView1.mas_right);
        make.top.equalTo(self.imageTitleView1.mas_top).offset(0.f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView2.mas_right);
        make.top.equalTo(self.imageTitleView2.mas_top).offset(0.f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView3.mas_right);
        make.top.equalTo(self.imageTitleView3.mas_top).offset(0.f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView1).offset(0.f);
        make.top.equalTo(self.imageTitleView1.mas_bottom).offset(5.0f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView2).offset(0.f);
        make.top.equalTo(self.imageTitleView2.mas_bottom).offset(5.0f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView3).offset(0.f);
        make.top.equalTo(self.imageTitleView3.mas_bottom).offset(5.0f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView8 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView4).offset(0.f);
        make.top.equalTo(self.imageTitleView4.mas_bottom).offset(5.0f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
//    self.backgroundColor = [UIColor clearColor];
    [self layoutIfNeeded];
    self.viewHeight = self.imageTitleView5.frame.origin.y + self.imageTitleView5.frame.size.height + 18;
}

- (UIImageView *)topImageView {
    if (!_topImageView) {
        _topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bjc"]];
    }
    return _topImageView;
}

- (SDCycleScrollView *)cycleScrollView {
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"banner"]];
        _cycleScrollView.showPageControl = YES;
        _cycleScrollView.autoScrollTimeInterval = 3.0f;
        _cycleScrollView.backgroundColor = [UIColor clearColor];
        _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
        _cycleScrollView.currentPageDotColor = [UIColor colorWithHexString:kBgGreenColor alpha:1.0];
        _cycleScrollView.pageDotColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1.0];
        _cycleScrollView.layer.cornerRadius = 5.0f;
        _cycleScrollView.layer.masksToBounds = YES;
    }
    return _cycleScrollView;
}

-(BTRootImageTItleVIew *) imageTitleView1{
    if (!_imageTitleView1) {
        _imageTitleView1 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView1.title.text = @"通知";
        _imageTitleView1.menuId = @"540759249913020";
        _imageTitleView1.imageView.image = [UIImage imageNamed:@"tz"];
        _imageTitleView1.delegate = self;
    }
    return _imageTitleView1;
}

-(BTRootImageTItleVIew *) imageTitleView2{
    if (!_imageTitleView2) {
        _imageTitleView2 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView2.title.text = @"周历";
        _imageTitleView2.menuId = @"540759249913081";
        _imageTitleView2.imageView.image = [UIImage imageNamed:@"zl"];
        _imageTitleView2.delegate = self;
    }
    return _imageTitleView2;
}



-(BTRootImageTItleVIew *) imageTitleView3{
    if (!_imageTitleView3) {
        _imageTitleView3 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView3.title.text = @"值班记录";
        _imageTitleView3.menuId = @"540759249913022";
        _imageTitleView3.imageView.image = [UIImage imageNamed:@"zbju"];
        _imageTitleView3.delegate = self;
    }
    return _imageTitleView3;
}



-(BTRootImageTItleVIew *) imageTitleView4{
    if (!_imageTitleView4) {
        _imageTitleView4 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView4.title.text = @"巡堂记录";
        _imageTitleView4.menuId = @"540759249913024";
        _imageTitleView4.imageView.image = [UIImage imageNamed:@"xtjl"];
        _imageTitleView4.delegate = self;
    }
    return _imageTitleView4;
}

-(BTRootImageTItleVIew *) imageTitleView5{
    if (!_imageTitleView5) {
        _imageTitleView5 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView5.title.text = @"巡堂统计";
        _imageTitleView5.menuId = @"540759249913030";
        _imageTitleView5.imageView.image = [UIImage imageNamed:@"xttj"];
        _imageTitleView5.delegate = self;
    }
    return _imageTitleView5;
}
///
-(BTRootImageTItleVIew *) imageTitleView6{
    if (!_imageTitleView6) {
        _imageTitleView6 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView6.title.text = @"听评课";
        _imageTitleView6.menuId = @"540759249913165";
        _imageTitleView6.imageView.image = [UIImage imageNamed:@"tpk-1"];
        _imageTitleView6.delegate = self;
    }
    return _imageTitleView6;
}



-(BTRootImageTItleVIew *) imageTitleView7{
    if (!_imageTitleView7) {
        _imageTitleView7 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView7.title.text = @"评教评学";
        _imageTitleView7.menuId = @"540759249913166";

        _imageTitleView7.imageView.image = [UIImage imageNamed:@"pjpx"];
        _imageTitleView7.delegate = self;
    }
    return _imageTitleView7;
}

-(BTRootImageTItleVIew *) imageTitleView8{
    if (!_imageTitleView8) {
        _imageTitleView8 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView8.title.text = @"教师就餐";
        _imageTitleView8.menuId = @"540759249913032";
        _imageTitleView8.imageView.image = [UIImage imageNamed:@"jctj"];
        _imageTitleView8.delegate = self;
    }
    return _imageTitleView8;
}

#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    if ([self.delegate respondsToSelector:@selector(homeRootHeaderDidClickBanner:)]) {
        [self.delegate homeRootHeaderDidClickBanner:self.wheelBannerList[index]];
    }
}

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index{
    
}


#pragma mark - BTRootImageTitleViewDelegate
-(void) rootImageViewDidTap:(BTRootImageTItleVIew *)imageTitleView
{
    if (imageTitleView == self.imageTitleView1) {
        if ([self.delegate respondsToSelector:@selector(homeRootHeaderDidClickNotice:)]) {
            [self.delegate homeRootHeaderDidClickNotice:imageTitleView.menuId];
        }
    }else if (imageTitleView == self.imageTitleView2) {
        if ([self.delegate respondsToSelector:@selector(homeRootHeaderDidClickCalendar:)]) {
            [self.delegate homeRootHeaderDidClickCalendar:imageTitleView.menuId];
        }
    }else if (imageTitleView == self.imageTitleView3) {
        if ([self.delegate respondsToSelector:@selector(homeRootHeaderDidClickDutyRecord:)]) {
            [self.delegate homeRootHeaderDidClickDutyRecord:imageTitleView.menuId];
        }
    }else if (imageTitleView == self.imageTitleView4) {
        if ([self.delegate respondsToSelector:@selector(homeRootHeaderDidClickPatrolHallRecord:)]) {
            [self.delegate homeRootHeaderDidClickPatrolHallRecord:imageTitleView.menuId];
        }
    }else if (imageTitleView == self.imageTitleView5) {
        if ([self.delegate respondsToSelector:@selector(homeRootHeaderDidClickPatrolHallStatistics:)]) {
            [self.delegate homeRootHeaderDidClickPatrolHallStatistics:imageTitleView.menuId];
        }
    }else if (imageTitleView == self.imageTitleView6) {
        if ([self.delegate respondsToSelector:@selector(homeRootHeaderDidClickAttendance:)]) {
            [self.delegate homeRootHeaderDidClickAttendance:imageTitleView.menuId];
        }
    }else if (imageTitleView == self.imageTitleView7) {
        if ([self.delegate respondsToSelector:@selector(homeRootHeaderDidClickTeachingLearn:)]) {
            [self.delegate homeRootHeaderDidClickTeachingLearn:imageTitleView.menuId];
        }
    }else if (imageTitleView == self.imageTitleView8) {
        if ([self.delegate respondsToSelector:@selector(homeRootHeaderDidClickDineStatistics:)]) {
            [self.delegate homeRootHeaderDidClickDineStatistics:imageTitleView.menuId];
        }
    }
}


@end
